﻿
using Repositories.Interfaces;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
using System;
namespace Repositories.Implementations
{
    public class ComboRepository : BaseRepository<Combo>, IComboRepository
    {
        public ComboRepository()
            : base()
        {
        }
        /// <summary>
        /// Gets the name of the entity set.
        /// </summary>
        /// <value>The name of the entity set.</value>
        protected override string EntitySetName
        {
            get
            {
                return "ASE_DatabaseEntities.Combo";
            }
        }

        public void Refresh()
        {
            ASEDbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, ASEDbContext.Combo);
        }

        private IComboRepository _ComboRepository;

        /// <summary>
        /// Gets the Combo repository.
        /// </summary>
        /// <value>The Combo repository.</value>
        public IComboRepository ComboRep
        {
            get
            {
                if (_ComboRepository == null)
                {
                    _ComboRepository = DIHelper.Resolve<IComboRepository>();
                }
                return _ComboRepository;
            }
        }




        /// <summary>
        /// Creates the Combo.
        /// </summary>
        /// <param name="item">The item.</param>
        public void CreateCombo(Combo item)
        {
            ComboRep.Insert(item);
        }

        /// <summary>
        /// Queries the Combo.
        /// </summary>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Query results.</returns>
        public IQueryable<Combo> QueryCombo(Expression<Func<Combo, bool>> predicate)
        {
            return ComboRep.GetQuery(predicate);
        }

        /// <summary>
        /// Finds the by ID.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>The Combo with input ID.</returns>
        public Combo FindById(int id)
        {
            IQueryable<Combo> returnValue = ComboRep.GetQuery(itm => itm.Id == id);
            if (!returnValue.Any())
                return null;
            return returnValue.FirstOrDefault();
        }

        /// <summary>
        /// Gets all Combo.
        /// </summary>
        /// <returns>all Combo.</returns>
        public List<Combo> GetAllCombo()
        {
            IQueryable<Combo> returnValue = ComboRep.GetQuery();
            if (!returnValue.Any())
                return null;
            return returnValue.ToList();
        }


        public Combo GetComboByOrder(int order)
        {
            IQueryable<Combo> returnValue = ComboRep.GetQuery(itm => itm.IndexNumber == order);
            if (!returnValue.Any())
                return null;
            return returnValue.FirstOrDefault();
        }

        /// <summary>
        /// Edits the Combo.
        /// </summary>
        /// <param name="item">The item.</param>
        public void EditCombo(Combo item)
        {
            ComboRep.Update(item);
        }


        /// <summary>
        /// Deletes the Combo.
        /// </summary>
        /// <param name="item">The item.</param>
        public void DeleteCombo(Combo item)
        {
            ComboRep.Delete(item);
        }


        /// <summary>
        /// Deattaches the specified category.
        /// </summary>
        /// <param name="category">The category.</param>
        public void Deattach(Category category)
        {

        }

        /// <summary>
        /// Deattaches the specified Combo.
        /// </summary>
        /// <param name="solicitation">The Combo.</param>
        public void DeattachTo(Combo combo)
        {
            ComboRep.DeattachTo(combo);
        }

        /// <summary>
        /// Applies the changes to database.
        /// </summary>
        public void ApplyTheChanges()
        {
            ComboRep.UnitOfWork.SaveChanges();
        }

        /// <summary>
        /// Accepts all changes.
        /// </summary>
        public void AcceptAllChanges()
        {
            ComboRep.UnitOfWork.AcceptAllChanges();
        }


    }
}
